import { defineStore } from "pinia"

export const useUserStore = defineStore("user", {
    state(): {
        infoArr: IuserMenus[]
        name: string
    } {
        return {
            infoArr: [],
            name: ""
        }
    },
    getters: {
        activeMenus() {
            const arr: IActive[] = this.infoArr.filter((item) => item.parentId === 0)

            this.infoArr.forEach((item) => {
                let p = arr.find((p) => p.id === item.parentId && item.hidden === 0)

                if (p) {
                    if (!p.children) {
                        p.children = []
                    }
                    p.children.push(item)
                }

            })
            return arr
        }
    },
}) 
